﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WFApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cboFuHao.SelectedIndex = 0;
        }

        private void btnJs_Click(object sender, EventArgs e)
        {
            decimal d1, d2;
            if (!decimal.TryParse(txtNum.Text, out d1))
            {
                labMsg.Text = "必须为数字类型！";
                labMsg.ForeColor = Color.Red;
                txtNum.Focus();
                return;
            }
            if (!decimal.TryParse(txtNum2.Text, out d2))
            {
                labMsg.Text = "必须为数字类型！";
                labMsg.ForeColor = Color.Red;
                txtNum2.Focus();
                return;
            }
            try
            {
                switch (cboFuHao.SelectedItem.ToString().Trim())
                {
                    case "+":
                        txtResult.Text = (d1 + d2).ToString();
                        break;
                    case "-":
                        txtResult.Text = (d1 - d2).ToString();
                        break;
                    case "*":
                        txtResult.Text = (d1 * d2).ToString();
                        break;
                    case "/":
                        txtResult.Text = (d1 / d2).ToString();
                        break;
                    case "%":
                        txtResult.Text = (d1 % d2).ToString();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                labMsg.Text = ex.Message;
                labMsg.ForeColor = Color.Red;
                return;
            }
           
        }
    }
}
